home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 22 / 4 / DISK2247.ZIP / CBASE101.ZIP / CBASE.ZIP / CBPUTR.C < prev    next >
Text File  |  1990-06-21  |  3KB  |  109 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbputr.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8.  
  9. /* library headers */
  10. #include <lseq.h>
  11.  
  12. /* local headers */
  13. #include "cbase_.h"
  14.  
  15. /*man---------------------------------------------------------------------------
  16. NAME
  17.      cbputr - put cbase record
  18.  
  19. SYNOPSIS
  20.      #include <cbase.h>
  21.  
  22.      int cbputr(cbp, buf)
  23.      cbase_t *cbp;
  24.      const void *buf;
  25.  
  26. DESCRIPTION
  27.      The cbputr function overwrites the current record of cbase cbp.
  28.      The record cursor and all key cursors are positioned to the
  29.      modified record.
  30.  
  31.      If the new record contents cannot be inserted because of an
  32.      illegal duplicate key, the original record is not restored.
  33.      More complete control of the actions taken to exceptions such as
  34.      this can be gained by overwriting a record using a series of
  35.      function calls to search, delete, and insert, rather than a
  36.      single call to cbputr.
  37.  
  38.      cbputr will fail if one or more of the following is true:
  39.  
  40.      [EINVAL]       cbp is not a valid cbase pointer.
  41.      [EINVAL]       buf is the NULL pointer.
  42.      [CBEDUP]       A field in the record pointed to by buf contains
  43.                     an illegal duplicate key.
  44.      [CBELOCK]      cbp is not write locked.
  45.      [CBENOPEN]     cbp is not open.
  46.      [CBENREC]      The record cursor of cbp is null.
  47.  
  48. SEE ALSO
  49.      cbdelcur, cbgetr, cbinsert, cbrcursor.
  50.  
  51. DIAGNOSTICS
  52.      Upon successful completion, a value of 0 is returned.  Otherwise,
  53.      a value of -1 is returned, and errno set to indicate the error.
  54.  
  55. ------------------------------------------------------------------------------*/
  56. int cbputr(cbp, buf)
  57. cbase_t *cbp;
  58. const void *buf;
  59. {
  60.     /* validate arguments */
  61.     if (!cb_valid(cbp)) {
  62.         errno = EINVAL;
  63.         return -1;
  64.     }
  65.     if (buf == NULL) {
  66.         errno = EINVAL;
  67.         return -1;
  68.     }
  69.  
  70.     /* check if not open */
  71.     if (!(cbp->flags & CBOPEN)) {
  72.         errno = CBENOPEN;
  73.         return -1;
  74.     }
  75.  
  76.     /* check if not write locked */
  77.     if (!(cbp->flags & CBWRLCK)) {
  78.         errno = CBELOCK;
  79.         return -1;
  80.     }
  81.  
  82.     /* check if record cursor is null */
  83.     if (lscursor(cbp->lsp) == NULL) {
  84.         errno = CBENREC;
  85.         return -1;
  86.     }
  87.  
  88.     /* delete current record */
  89.     if (cbdelcur(cbp) == -1) {
  90.         CBEPRINT;
  91.         return -1;
  92.     }
  93.  
  94.     /* back up cursor */
  95.     if (cbrecprev(cbp) == -1) {
  96.         CBEPRINT;
  97.         return -1;
  98.     }
  99.  
  100.     /* insert new record */
  101.     if (cbinsert(cbp, buf) == -1) {
  102.         CBEPRINT;
  103.         return -1;
  104.     }
  105.  
  106.     errno = 0;
  107.     return 0;
  108. }
  109.